<link rel="stylesheet" href="assets/store/css/goods.css?v=<?= $version ?>">
<link rel="stylesheet" href="assets/common/plugins/umeditor/themes/default/css/umeditor.css">
<style>
    .table_box{
        min-width: 1000px;
    }

    .table_box .table-title{
       line-height: 30px;
    }
    .table_box .table-fbt{
        line-height: 30px;
    }
    .table_box th{
        display: block;
    }
    .table_box .table-title th,.table-fbt th{
        width: 100%;
        text-align: center;
    }
    .table_box td{
        text-align: center;
    }
    .table_box tbody{
        display: table;
        width: 100%;
    }

    .table_box input,textarea{
        outline: 0;
        border: 0;
    }
    </style>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">基本信息</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-1 am-u-lg-1 am-form-label form-require"> 教练 </label>
                                <div class="am-u-sm-3 am-u-end">
                                    <select name="fitness[coach_id]" id="coach" data-am-selected="{searchBox: 1, btnSize: 'sm', placeholder:'请选择', maxHeight: 400}"
                                            required>
                                        <option value=""></option>
                                        <?php if (isset($coachList) && !$coachList->isEmpty()):
                                            foreach ($coachList as $item): ?>
                                                <option value="<?= $item['coach_id'] ?>"><?= $item['real_name'] ?></option>
                                            <?php endforeach; endif; ?>
                                    </select>
                                    <div class="help-block">
                                        <small></small>
                                    </div>
                                </div>
                                <div class="am-u-sm-3 am-u-end">
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="fitness[date]"
                                               class="am-form-field"
                                               value="" placeholder="阶段日期" data-am-datepicker>
                                    </div>
                                </div>
                                <div class="am-u-sm-3 am-u-end">
                                    <div class="am-btn am-btn-xs am-btn-secondary" @click="add_stage">添加阶段</div>
                                </div>
                            </div>
                            <div class="tablebox">
                                <table class="table_box" border="1" cellspacing="0" cellpadding="0">
                                   <thead>
                                   <tr class="table-title"><th>MOD拳击健身馆</th></tr>
                                   <tr class="table-fbt"><th><input type="text" name="fitness[title]" value="" placeholder="eg:训练计划阶段" style="text-align: center"></th></tr>
                                   </thead>
                                    <tbody v-for="(item,index) in stage" :key="index">
                                        <tr >
                                            <td colspan="2" >
                                                <a @click="delete_item(index)" href="javascript:;" class="item-delete tpl-table-black-operation-del" style="position: absolute;left: 60px;display: none" v-show="index > 0">
                                                    <i class="am-icon-trash"></i>
                                                </a>
                                                <span>阶段名称</span>
                                            </td>
                                            <td colspan="8" ><input type="text" v-model="stage[index].title"></td>
                                        </tr>
                                        <tr>
                                            <td colspan="10" >
                                                <textarea name="" id="" cols="30" rows="5" v-model="stage[index].content"></textarea>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            <!-- 表单提交按钮 -->
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>

                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="assets/common/js/vue.min.js"></script>
<script src="assets/common/js/ddsort.js"></script>
<script src="assets/common/plugins/umeditor/umeditor.config.js?v=<?= $version ?>"></script>
<script src="assets/common/plugins/umeditor/umeditor.min.js"></script>
<script src="assets/store/js/goods.spec.js?v=<?= $version ?>"></script>
<script>

    $(function () {
        var setting = {
            el: 'many-app',
            baseData: null,
        };
        function Fitness(options){
            setting =  $.extend(true, {}, setting,options);
            this.initialize()
        }
        Fitness.prototype = {
            appVue:null,
            initialize:function () {
                var stage = [
                    {number:'一',title:'',content:''},
                ]
                if (typeof setting.baseData !== 'undefined' && setting.baseData !== null) {
                    stage = setting.baseData['stage'];
                }
                this.appVue = new Vue({
                    el: '#my-form',
                    data: {
                        stage:stage,
                        test:''
                    },
                    methods:{
                        getData: function () {
                            return this.$data;
                        },
                        setData:function (data) {
                            this.test = data
                            console.log(data)
                        },
                        delete_item(index){
                            let that = this
                            layer.confirm('确定删除吗',function (index2) {
                                layer.close(index2)
                                that.stage.splice(index,1)
                            })

                        },
                        add_stage:function () {
                            this.stage.push({
                                number:'',title:"",content:''
                            })
                        }
                    },
                })
            }
        }
        window.Fitness = Fitness
        // 注册商品多规格组件
        var specMany = new Fitness({
            el: '#my-form',
        });
        $("#coach").change(function () {
            specMany.appVue.setData($(this).val())
        })
        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm({
            // 获取多规格sku数据
            buildData: function () {
                var specData = specMany.appVue.getData();
                return {
                    fitness: {data:specData,date:''}
                };
            },
            // 自定义验证
            validation: function () {
                var title = $('input[name="fitness[title]"]').val();
                var date = $('input[name="fitness[date]"]').val();
                if (title === '' || title === undefined) {
                    layer.msg('请输入表头');
                    return false;
                }
                if (date === '' || date === undefined) {
                    layer.msg('请选择阶段日期');
                    return false;
                }
                return true
            }
        });
    });
</script>
